// DriveNotes. Copyright (c) 2011, Andrei Senchuk. All rights reserved.
package net.taviscaron.drivenotes.web.converter;

import java.util.Map;
import net.taviscaron.drivenotes.shared.model.entity.Service;
import net.taviscaron.drivenotes.web.util.ParamUtils;

/**
 * Service converter
 * @author Andrei Senchuk
 */
public class ServiceConverter extends FormConverter<Service> {

    @Override
    public Service convert(Map params, String prefix) throws InvalidFormException {
        Service service = new Service();
        try {
                service.setId(ParamUtils.parseLongParam(params, "id", prefix));
                service.setProblems(ParamUtils.parseStringParam(params, "problems", prefix));
                service.setSpares(ParamUtils.parseStringParam(params, "spares", prefix));
                service.setComment(ParamUtils.parseStringParam(params, "comment", prefix));
                service.setServiceCost(ParamUtils.parseFloatParam(params, "serviceCost", prefix));
                service.setSparesCost(ParamUtils.parseFloatParam(params, "sparesCost", prefix));
                service.setOdometrValue(ParamUtils.parseIntParam(params, "odometrValue", prefix));
        } catch (IllegalArgumentException e) {
            throw new InvalidFormException();
        }
        return service;
    }
}
